package pers.lmd.config;

import cn.dev33.satoken.stp.StpInterface;
import cn.hutool.core.convert.Convert;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import pers.lmd.domain.entity.Menu;
import pers.lmd.service.IMenuService;
import pers.lmd.service.IRoleService;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author lmd
 * @Date 2023/5/20 19:34
 */
@Component
@RequiredArgsConstructor
public class StpPermissionImpl implements StpInterface {

    private final IRoleService roleService;
    private final IMenuService menuService;

    /**
     * 返回一个账号所拥有的权限码集合
     *
     * @param loginId  用户id
     * @param menuType 菜单类型
     */
    @Override
    public List<String> getPermissionList(Object loginId, String menuType) {
        return menuService.getPermissionByUid(Convert.toBigInteger(loginId));
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        return roleService.getRole(Convert.toBigInteger(loginId));
    }
}
